﻿using System;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using UnityEngine.UI;

// Token: 0x02000005 RID: 5
public class BloodDamageUI : MonoBehaviour
{
	// Token: 0x0600000B RID: 11 RVA: 0x00002E0C File Offset: 0x0000100C
	public void SetNostalgiaMode(bool nost)
	{
		this.nostalgiaMode = nost;
		if (this.nostalgiaMode)
		{
			QualitySettings.vSyncCount = 0;
			Application.targetFrameRate = 30;
			Screen.SetResolution(1280, 720, FullScreenMode.Windowed);
			this.nostalgiaModeObj.SetActive(true);
			this.postProcess.enabled = false;
			return;
		}
		QualitySettings.vSyncCount = 0;
		Application.targetFrameRate = -1;
		Screen.SetResolution(Screen.resolutions[Screen.resolutions.Length - 1].width, Screen.resolutions[Screen.resolutions.Length - 1].height, FullScreenMode.FullScreenWindow);
		this.nostalgiaModeObj.SetActive(false);
		this.postProcess.enabled = true;
	}

	// Token: 0x0600000C RID: 12 RVA: 0x00002EB8 File Offset: 0x000010B8
	private void Start()
	{
		BloodDamageUI.main = this;
		this.postProcess = Camera.main.GetComponent<Volume>();
		this.curOpacity = 1f;
		this.SetNostalgiaMode(false);
		this.postProcess.profile.TryGet<ColorAdjustments>(out this.clr);
		this.postProcess.profile.TryGet<FilmGrain>(out this.grain);
		this.postProcess.profile.TryGet<DepthOfField>(out this.blur);
		if (!PlayerPrefs.HasKey("lowHpVol"))
		{
			PlayerPrefs.SetFloat("lowHpVol", 0.8f);
		}
		this.healthVolMult = PlayerPrefs.GetFloat("lowHpVol");
		GameObject gameObject = (GameObject)Object.Instantiate(Resources.Load("PickupObj"), Vector2.zero, Quaternion.identity);
		this.pickupSprite = gameObject.GetComponent<SpriteRenderer>();
	}

	// Token: 0x0600000D RID: 13 RVA: 0x00002F8D File Offset: 0x0000118D
	public void ChangeLowHealthVol(float change)
	{
		PlayerPrefs.SetFloat("lowHpVol", Mathf.Clamp01(PlayerPrefs.GetFloat("lowHpVol") + change));
		this.healthVolMult = PlayerPrefs.GetFloat("lowHpVol");
		this.healthVolMult = Mathf.Clamp01(this.healthVolMult);
	}

	// Token: 0x0600000E RID: 14 RVA: 0x00002FCB File Offset: 0x000011CB
	public void EnemyKilled()
	{
		this.clr.contrast.value += 15f;
	}

	// Token: 0x0600000F RID: 15 RVA: 0x00002FEC File Offset: 0x000011EC
	private void Update()
	{
		if (this.body)
		{
			this.desiredIncrease -= Time.deltaTime * 50f;
			this.desiredIncrease += Mathf.Clamp(this.prevHealth - this.body.health, 0f, 15f);
			this.desiredIncrease = Mathf.Clamp(this.desiredIncrease, 0f, 15f);
			this.curIncrease = Mathf.Lerp(this.curIncrease, this.desiredIncrease * 0.09f, Time.deltaTime * 20f);
			this.prevHealth = this.body.health;
			this.curOpacity = Mathf.Lerp(this.curOpacity, this.body.health / this.body.maxHealth, 4f * Time.deltaTime);
			this.image.color = new Color(this.body.bloodColor.r, this.body.bloodColor.g, this.body.bloodColor.b, Mathf.Clamp(1f - this.curOpacity - 0.15f + this.curIncrease, 0f, 1f));
			float num = 0.5f - this.body.health / this.body.maxHealth * 0.7f;
			this.lowHealthAudio.volume = Mathf.Lerp(this.lowHealthAudio.volume, num * this.healthVolMult, 4f * Time.unscaledDeltaTime);
			if (this.body.health < 0f && !this.playedCorpusSound)
			{
				this.lowHealthAudio.Stop();
				Sound.Play(Resources.Load<AudioClip>("Sounds/corpusBreak"), Vector2.zero, true, false, this.healthVolMult);
				this.playedCorpusSound = true;
			}
			this.grain.intensity.value = Mathf.Lerp(this.grain.intensity.value, (1f - this.curOpacity - 0.2f) / 0.8f, 4f * Time.deltaTime);
			this.blur.focusDistance.value = Mathf.Lerp(this.blur.focusDistance.value, Mathf.Lerp(100f, 70f, 1f - this.body.health / this.body.maxHealth), 4f * Time.deltaTime);
			if (this.body.held)
			{
				if (!this.wepImg.gameObject.activeSelf)
				{
					this.wepImg.gameObject.SetActive(true);
				}
				this.wepImg.GetComponent<RectTransform>().anchoredPosition = Camera.main.WorldToScreenPoint(this.body.held.transform.position) + Vector3.up * 150f;
				if (this.body.heldFirearm)
				{
					this.wepImg.fillAmount = (float)this.body.heldFirearm.ammo / (float)this.body.heldFirearm.maxAmmo;
				}
				else
				{
					this.wepImg.fillAmount = this.body.held.durability / this.body.held.maxDurability;
				}
			}
			else if (this.wepImg.gameObject.activeSelf)
			{
				this.wepImg.gameObject.SetActive(false);
			}
			this.pickupSprite.sprite = null;
			if (this.body.pickupCooldown <= 0f && !this.body.holdingMain && this.body.canPickup)
			{
				Collider2D[] array = Physics2D.OverlapCircleAll(this.body.torso.transform.position, 3f);
				for (int i = 0; i < array.Length; i++)
				{
					WeaponScript weaponScript;
					if (array[i].TryGetComponent<WeaponScript>(out weaponScript) && !weaponScript.held)
					{
						this.pickupSprite.sprite = weaponScript.rend.sprite;
						this.pickupSprite.transform.position = weaponScript.transform.position;
						this.pickupSprite.transform.rotation = weaponScript.transform.rotation;
						this.pickupSprite.transform.localScale = weaponScript.transform.localScale;
						this.pickupSprite.color = new Color(2f - weaponScript.durability / weaponScript.maxDurability * 2f, weaponScript.durability / weaponScript.maxDurability * 2f, 0f, Mathf.PingPong(Time.time * 2f, 1f));
						break;
					}
				}
			}
		}
		this.clr.contrast.value -= Time.deltaTime * 20f;
		this.clr.contrast.value = Mathf.Clamp(this.clr.contrast.value, 0f, 50f);
	}

	// Token: 0x0400001C RID: 28
	public float curOpacity = 1f;

	// Token: 0x0400001D RID: 29
	public BodyScript body;

	// Token: 0x0400001E RID: 30
	public Image image;

	// Token: 0x0400001F RID: 31
	public Image wepImg;

	// Token: 0x04000020 RID: 32
	public bool nostalgiaMode;

	// Token: 0x04000021 RID: 33
	public GameObject nostalgiaModeObj;

	// Token: 0x04000022 RID: 34
	public Volume postProcess;

	// Token: 0x04000023 RID: 35
	private ColorAdjustments clr;

	// Token: 0x04000024 RID: 36
	private FilmGrain grain;

	// Token: 0x04000025 RID: 37
	public AudioSource lowHealthAudio;

	// Token: 0x04000026 RID: 38
	[HideInInspector]
	public bool playedCorpusSound;

	// Token: 0x04000027 RID: 39
	public static BloodDamageUI main;

	// Token: 0x04000028 RID: 40
	private DepthOfField blur;

	// Token: 0x04000029 RID: 41
	private float desiredIncrease;

	// Token: 0x0400002A RID: 42
	private float curIncrease;

	// Token: 0x0400002B RID: 43
	private float prevHealth;

	// Token: 0x0400002C RID: 44
	[HideInInspector]
	public float healthVolMult;

	// Token: 0x0400002D RID: 45
	private SpriteRenderer pickupSprite;
}
